package com.bnyy.medicalHousekeeper.moudle.message.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bnyy.common.adapter.BaseNormalListAdapter;
import com.bnyy.medicalHousekeeper.DialogHelper;
import com.bnyy.medicalHousekeeper.R;
import com.bnyy.medicalHousekeeper.UserInfoManager;
import com.bnyy.medicalHousekeeper.activity.MainActivity;
import com.bnyy.medicalHousekeeper.request.RequestManager;
import com.bnyy.message.bean.chat.ChatMessage;
import com.bnyy.message.bean.chat.message_data.NoticeAlarmMessage;

import org.greenrobot.eventbus.EventBus;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

/**
 * Author : 关炳鹏
 * Description :
 * Date : 2023/1/9
 **/
public class NoticeAlarmAdapter extends BaseNormalListAdapter<ChatMessage, NoticeAlarmAdapter.ViewHolder> {

    public NoticeAlarmAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(inflater.inflate(R.layout.item_message_notice_alarm, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);

        ChatMessage chatMessage = getData(position);

        NoticeAlarmMessage noticeAlarmMessage = (NoticeAlarmMessage) chatMessage.getMessageData();
        holder.tvTitle.setText(noticeAlarmMessage.getTitle());

        holder.tvTime.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date(chatMessage.getTime())));
        holder.tvContent.setText(chatMessage.getContent());

        holder.root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HashMap<String, String> params = new HashMap<>();
                params.put("alarm_uuid", noticeAlarmMessage.getAlarm_uuid());
                RequestManager requestManager = RequestManager.getInstance();

//                requestManager.request(requestManager.mAlarmJavaRetrofitService.getAlarmProcedureInfo(RequestManager.getJsonRequestBody(params)),
//                        new BaseObserverImpl<ArrayList<AlarmInfo>>(mContext) {
//                            @Override
//                            public void onSuccess(ArrayList<AlarmInfo> alarmInfos) {
//                                super.onSuccess(alarmInfos);
//                                if (alarmInfos.get(alarmInfos.size() - 1).getMsg_type() == AlarmSocketTag.ALARM_GROUP_FINISH) {
//                                    AlarmLocationActivity.show(mContext, alarmInfos.get(0));
//                                } else {
//                                    EventBus.getDefault().post(new AlarmEvent(AlarmEvent.Type.SWITCH_ALARM, alarmInfos.get(0)));
//                                    MainActivity.show(mContext);
//                                }
//                            }
//                        });
            }
        });
    }

    public static class ViewHolder extends BaseNormalListAdapter.ViewHolder {

        TextView tvTime;
        TextView tvContent;
        TextView tvTitle;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);

            tvTime = itemView.findViewById(R.id.tv_time);
            tvContent = itemView.findViewById(R.id.tv_content);
            tvTitle = itemView.findViewById(R.id.tv_title);
        }
    }
}
